package demoMod.stsconsole.events;

import demoMod.stsconsole.helpers.LocalizedStrings;
import demoMod.stsconsole.helpers.PromptHelper;
import demoMod.stsconsole.rooms.EventRoom;

import java.util.List;

public abstract class AbstractEvent {
    public final String id;
    protected List<String> eventStrings;
    private final EventNode rootNode;
    protected boolean updateBodyTextAfterChooseOption = true;

    public AbstractEvent(String id) {
        this.id = id;
        this.eventStrings = LocalizedStrings.getEventStrings(id);
        this.rootNode = initOptions();
        PromptHelper.appendPrompt("Event");
    }

    protected abstract EventNode initOptions();

    public void updateBodyText() {
        System.out.println(this.rootNode.getUpdatedDescription());
        System.out.println();
        int index = 0;
        for (String option : this.rootNode.getChoices()) {
            System.out.println(index + "\t" + option);
            index++;
        }
    }

    public void onChooseOption(int optionIndex) {
        this.rootNode.onChooseOption(optionIndex);
        if (updateBodyTextAfterChooseOption) updateBodyText();
    }

    public List<String> getEventStrings() {
        return this.eventStrings;
    }

    public EventNode getCurrNode() {
        return rootNode.getNode();
    }

    public void dropReward(EventRoom eventRoom, boolean shouldDropReward) {

    }
}
